gVisTimeSeries <- function(datetime, 
                           prm1, 
                           prm2, 
                           data, 
                           chartname, 
                           outputfilepath) {
  
################################################################################
##  
##  This program produces html output which plots 2 meteorological parameters 
##  as a zoomable time series line plot. 
##  
##  
##  function parameters are as follows:
##  
##  datetime (character): Datetime of the observations.
##                        Format must be 'YYYY-MM-DD hh:mm:ss'
##  prm1 (character):     The first parameter to be plotted
##  prm2 (character):     The second parameter to be plotted
##  data:                 Data frame where prm1 and prm2 can be found.
##  chartname 
##  (character):          The name that will be printed with the chart.
##  outputfilepath
##  (character):          Filepath and name where "....htm" file should be saved.
##
################################################################################
##
##  Copyright (C) 2012 Tim Appelhans
##
##  This program is free software: you can redistribute it and/or modify
##  it under the terms of the GNU General Public License as published by
##  the Free Software Foundation, either version 3 of the License, or
##  (at your option) any later version.
##
##  This program is distributed in the hope that it will be useful,
##  but WITHOUT ANY WARRANTY; without even the implied warranty of
##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
##  GNU General Public License for more details.
##
##  You should have received a copy of the GNU General Public License
##  along with this program.  If not, see <http://www.gnu.org/licenses/>.
##
##  Please send any comments, suggestions, criticism, or (for our sake) bug
##  reports to tim.appelhans@gmail.com
##
################################################################################
  
  
######################## FUNCTION BODY #########################################  
  
  ## REQUIRE NECESSARY LIBRARIES (ERROR IF NOT INSTALLED)
  stopifnot(require(googleVis))
  stopifnot(require(reshape))
  
  ## READ PRMs AND DATETIME INTO DF
  df <- data.frame(Datetime = data[datetime],
                   prm1 = data[prm1],
                   prm2 = data[prm2])
  
  ## MELT DF FROM WIDE TO LONG FORMAT
  df.melt <- melt(df, id.vars = "Datetime", 
                  measure.vars = c(prm2, prm1))
  
  ## CONVERT CHARACTER TYPE DATETIME TO POSIX
  df.melt$Datetime <- strptime(df.melt$Datetime, "%Y-%m-%d %H:%M:%S")
  
  ## CREATE PLOT OBJECT 
  plot <- gvisAnnotatedTimeLine(df.melt, datevar = "Datetime", 
                                numvar = "value",
                                idvar = "variable",
                                chartid = chartname,
                                options = list(
                                  scaleColumns = '[0,1]',
                                  scaleType = "allmaximized",
                                  fill = 5, width = 1024))
  
  ## PRINT HTML PART OF PLOT TO OUTPUTFILEPATH
  print(plot, tag = "html", file = outputfilepath) 
}

          